<?php

namespace App\Http\Middleware;

use Closure;
use Auth;
//在app\http\kernel.php中$routeMiddleware里添加 'checkLogin' => CheckLogin::class,
class CheckLogin
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)

    {
        //判断用户是否登录，如果登陆了，就算了，如果没登陆，就去登录
        if (!Auth::check()){
            //设置闪存信息
            session()->flash('danger','请先登录');
            //跳转页面
            return redirect()->route('login');
        }


        return $next($request);

    }
}
